<template>
	<view class="container">
		<!-- 首页-搜索框 -->
		<view class="cu-bar bg-white search " >
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input type="text" placeholder="请输入搜索" confirm-type="search" @input="searchIcon"></input>
			</view>
		</view>
		<!-- 轮播图 -->
		<view class="carousel-section">
			<!-- 标题栏和状态栏占位符 -->
			<view class="titleNview-placing"></view>
			<!-- 背景色区域 -->
			<view class="titleNview-background" :style="{backgroundColor:titleNViewBackground}"></view>
			<swiper class="screen-swiper"  :indicator-dots="true" :circular="true"
			 :autoplay="true" interval="5000" duration="500">
				<swiper-item v-for="(item,index) in carouselList" :key="index">
					<image :src="item.src" mode="aspectFill" style="width: 100%;height: 110%;"></image>
				</swiper-item>
			</swiper>
		</view>
		<!-- 分类 -->
		<view class="cate-section">
			<view class="cate-item">
				<image src="/static/temp/c3.png"></image>
				<text>家庭常备</text>
			</view>
			<view class="cate-item">
				<image src="/static/temp/c5.png"></image>
				<text>母婴乐园</text>
			</view>
			<view class="cate-item">
				<image src="/static/temp/c6.png"></image>
				<text>滋补保健</text>
			</view>
			<view class="cate-item">
				<image src="/static/temp/c7.png"></image>
				<text>器械商城</text>
			</view>
			<view class="cate-item">
				<image src="/static/temp/c8.png"></image>
				<text>专科用药</text>
			</view>
		</view>

		<view class="cu-list menu-avatar" @click="gourl()">

			<view class="cu-item " v-for="(item,index) in goodsList" :key="index">
				<view class="cu-avatar radius lg" :style="'background-image:url('+item.image+')'"></view>
				<view class="content">
					<view class="text-pink">
						<view class="text-cut">{{item.title}}</view>
					</view>
					<view class="text-gray text-sm flex">
						<view class="text-cut">{{item.desc}}</view>
					</view>
				</view>
				<view class="action">
					<view class="text-grey text-xs">{{item.time}}</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	export default {

		data() {
			return {
				CustomBar: 44,
				titleNViewBackground: '',
				swiperCurrent: 0,
				swiperLength: 0,
				carouselList: [{
						id: 1,
						src: "https://image.360kad.com/group2/M00/E2/A2/CgAgFF3mKPyAK4seAAMIOqdshoA353.jpg",
					},
					{
						id: 2,
						src: "http://image.360kad.com/group1/M00/64/0E/CgAgEVf4QviAVywgAAGlW8Bd-Fg152.jpg",
					},
					{
						id: 3,
						src: "http://image.360kad.com/group1/M00/A5/BA/CgAgEVke7-OAPphVAAGqUHy4p5U657.jpg",
					},
					{
						id: 4,
						src: "http://image.360kad.com/group1/M00/94/66/CgAgEFjTz7mAT8eEAAGn-eTYPhg156.jpg",
					},
					{
						id: 5,
						src: "http://image.360kad.com/group1/M00/93/E7/CgAgEVjSHjiAQaSgAAGe97nIMzU092.jpg",
					}
				],
				/* 商品列表 */
				goodsList: [{
						image: "http://image.360kad.com/group1/M00/98/6E/CgAgEVjmEASAa1XHAAL7q3BnObo120.jpg",
						title: "绿A 天然螺旋藻精片 150g(0.5g*12片*25袋)",
						desc: '云南绿A生物工程有限公司',
						time: '22:20',
					},
					{
						image: "http://image.360kad.com/group1/M00/A5/B5/CgAgEVke5fCATSsWAAGcCEi5Xck701.jpg",
						title: "汤臣倍健 螺旋藻咀嚼片(美国螺旋藻粉) 600mg*30片",
						desc: '汤臣倍健股份有限公司',
						time: '22:30',
					},
					{
						image: "http://image.360kad.com/group2/M00/42/79/CgAgFFqrqHWAXCDyAAF8AxkaRps571.jpg",
						title: "佛慈 阿胶 250g(31.25g*8块) 补血滋阴，润燥止血",
						desc: '兰州佛慈制药股份有限公司',
						time: '22:25',
					},
					{
						image: "http://image.360kad.com/group2/M00/07/8E/CgAgFFnJzliAVGQ1AAG49eqNOdQ255.jpg",
						title: "善存 沛优牌辅助降血脂软胶囊 90g(1.0g*90粒)",
						desc: '仙乐健康科技股份有限公司',
						time: '22:20',
					},
					{
						image: "http://image.360kad.com/group2/M00/B4/E2/CgAgFF0HC5aAAJ8CAAMOA2m8NKw708.jpg",
						title: "【蛋白质营养粉】生命需宝 蛋白粉 500g/罐",
						desc: '广东长兴生物科技股份有限公司',
						time: '22:20',
					},
					{
						image: "http://image.360kad.com/group1/M00/64/0E/CgAgEVf4QviAVywgAAGlW8Bd-Fg152.jpg",
						title: "脑白金 脑白金胶囊+口服液(附礼盒袋) 0.25g*20粒+250ml*2瓶",
						desc: '无锡健特药业有限公司',
						time: '22:20',
					}
				],

			};
		},

		onLoad() {
			this.loadData();
		},
		methods: {
			/**
			 * 请求静态数据只是为了代码不那么乱
			 * 分次请求未作整合
			 */
			async loadData() {
				let carouselList = this.carouselList //await this.$api.json('carouselList');
				this.titleNViewBackground = carouselList[0].background;
				this.swiperLength = carouselList.length;
				this.carouselList = carouselList;

				let goodsList = this.goodsList //await this.$api.json('goodsList');
				this.goodsList = goodsList || [];
			},
			//轮播图切换修改背景色
			swiperChange(e) {
				const index = e.detail.current;
				this.swiperCurrent = index;
				this.titleNViewBackground = this.carouselList[index].background;
			},
			//详情页
			navToDetailPage(item) {
				//测试数据没有写id，用title代替
				let id = item.title;
				uni.navigateTo({
					url: `/pages/product/product?id=${id}`
				})
			},
			gourl() {
				uni.navigateTo({
					url: 'tabbar-1-detail',
					success: (res) => {
						console.log(res)
					},
					fail: (err) => {
						console.log(err)
					}
				})

			}
		},
	}
</script>

<style lang="scss">
	/* #ifdef MP */
	page {
		.cate-section {
			position: relative;
			z-index: 5;
			border-radius: 16upx 16upx 0 0;
			margin-top: -20upx;
		}

		.carousel-section {
			padding: 0;

			.titleNview-placing {
				padding-top: 0;
				height: 0;
			}

			.carousel {
				.carousel-item {
					padding: 0;
				}
			}

			.swiper-dots {
				left: 45upx;
				bottom: 40upx;
			}
		}
	}

	/* #endif */


	page {
		background: #f5f5f5;
	}

	/* 轮播图 */
	.carousel-section {
		padding: 0 0 0 0;
	}

	/* 分类 */
	.cate-section {
		display: flex;
		justify-content: space-around;
		align-items: center;
		flex-wrap: wrap;
		padding: 30upx 22upx;
		background: #fff;

		.cate-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			font-size: $font-sm + 2upx;
			color: $font-color-dark;
		}

		/* 原图标颜色太深,不想改图了,所以加了透明度 */
		image {
			width: 88upx;
			height: 88upx;
			margin-bottom: 14upx;
			border-radius: 50%;
			opacity: .7;
			box-shadow: 4upx 4upx 20upx rgba(250, 67, 106, 0.3);
		}
	}
</style>
